﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Controls;
using ThreeByte.ActiveDeck.Config;

namespace ThreeByte.ActiveDeck.Content
{
    public static class PagePreviewFactory
    {

        public static UserControl Create(PageConfig config) {
            //***** PREVIEW *****
            string previewTypeName = config.GetType().FullName;
            //TODO: Fix namespace problem
            previewTypeName = previewTypeName.Replace(".Config.", ".Content.");
            //TODO: Fix name conversion
            previewTypeName = previewTypeName.Replace("Config", "Preview");

            //use reflection to instantiate a configuration user control
            Type previewType = Type.GetType(previewTypeName, true);
            UserControl previewControl = (UserControl)previewType
                                .GetConstructor(new Type[] { config.GetType() })
                                .Invoke(new object[] { config });
            return previewControl;
        }
    }
}
